<!--
 * @Author: your name
 * @Date: 2020-12-20 10:24:14
 * @LastEditors: Please set LastEditors
 * @Description: 销售出库退库详情，该页面能点击审核和打印
 * @FilePath: \cang-chu-guan-li-xi-tong\src\views\chukuguanli\XiaoShouChuKuDetail.vue
-->
<template>
  <a-card>
    <p style="font-size: 18px; text-align: center">销售出库退库申请</p>
    <br />
    <a-form-model :model="Form" v-bind="layout"
      ><!-- 顶部的信息  -->
      <a-row>
        <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="单据号">
            <div>{{ Form.document }}</div>
          </a-form-model-item>
        </a-col>

        <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="仓库名称">
            <div>{{ Form.storname }}</div>
          </a-form-model-item>
        </a-col>

        <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="申请部门">
            <div>{{ Form.deptId_dictText }}</div>
          </a-form-model-item>
        </a-col>

        <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="客户">
            <div>{{ Form.clientId_dictText }}</div>
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="库存组织">
            <div>{{ Form.pkCalbody_dictText }}</div>
          </a-form-model-item>
        </a-col>
        <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="业务流程">
            <div>{{ Form.cbiztype_dictText }}</div>
          </a-form-model-item>
        </a-col>

        <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="单据日期">
            <div>{{ Form.document_date }}</div>
          </a-form-model-item>
        </a-col>

        <!-- <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="库存组织">
            <div>{{ Form.pkCalbody_dictText }}</div>
          </a-form-model-item>
        </a-col> -->
      </a-row>

      <!-- <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
        <a-form-model-item label="业务流程">
          <div>{{ Form.cbiztype_dictText }}</div>
        </a-form-model-item>
      </a-col> -->
    </a-form-model>

    <a-table
      :columns="columns"
      :data-source="dataSource"
      style="margin-top: 10px"
      :pagination="false"
    >
    </a-table>

    <div style="margin-top: 20px">
      <!-- 单据 -->
      <a-form-model :model="Form" v-bind="layout"
        ><!-- 顶部的信息 -->
        <a-row>
          <!-- <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
            <a-form-model-item label="负责人">
              <div>{{ Form.responsiblePerson }}</div>
            </a-form-model-item>
          </a-col> -->

          <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
            <a-form-model-item label="审核人">
              <div>{{ Form.inspector }}</div>
            </a-form-model-item>
          </a-col>

          <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
            <a-form-model-item label="审核日期">
              <div>{{ Form.balance }}</div>
            </a-form-model-item>
          </a-col>

          <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
            <a-form-model-item label="制单人">
              <div>{{ Form.singleProducerName }}</div>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>

      <!-- 提交按钮组  
      1. 能审核提交的人是不能点击保存的
      2. 能保存的人是不能审核和提交的
      -->
      <div style="margin-top: 20px">
        <center>
          <a-button style="margin-right: 20px" disabled> 保存 </a-button>

          <a-button
            @click="Examine"
            style="margin-right: 20px"
            :disabled="!alreadyCheckTag"
          >
            审核
          </a-button>
          <a-button
            @click="conCheck"
            style="margin-right: 20px"
            :disabled="alreadyCheckTag"
          >
            反审核
          </a-button>
          <!-- <a-button
            type="primary"
            @click="Submit"
            style="margin-right: 20px"
            :disabled="!alreadyRecordTag"
          >
            提交
          </a-button> -->

          <!-- <a-button
            type="primary"
            @click="save_u8c"
            style="margin-right: 20px"
            
          >
            同步至用友
          </a-button> -->
        </center>
      </div>
    </div>

    <div style="display: none">
      <div id="printCons" style="width: 94%; margin: 0 auto">
        <a-form-model :model="Form" v-bind="layout">
          <a-row>
            <a-col :xl="8" :lg="8" :md="12" :sm="24" :xs="24">
              <a-form-model-item label="单据号">
                <div>: {{ Form.document }}</div>
              </a-form-model-item>
            </a-col>

            <a-col :xl="8" :lg="8" :md="12" :sm="24" :xs="24">
              <a-form-model-item label="单据日期">
                <div>: {{ Form.document_date }}</div>
              </a-form-model-item>
            </a-col>

            <a-col :xl="8" :lg="8" :md="12" :sm="24" :xs="24">
              <a-form-model-item label="发货仓库">
                <div>: {{ Form.depotName }}</div>
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col :xl="8" :lg="8" :md="12" :sm="24" :xs="24">
              <a-form-model-item label="申请部门">
                <div>: {{ Form.department }}</div>
              </a-form-model-item>
            </a-col>

            <a-col :xl="8" :lg="8" :md="12" :sm="24" :xs="24">
              <a-form-model-item label="客户">
                <div>: {{ Form.client }}</div>
              </a-form-model-item>
            </a-col>

            <a-col :xl="8" :lg="8" :md="12" :sm="24" :xs="24">
              <a-form-model-item label="收发类别">
                <div>: {{ Form.sendReceiveType }}</div>
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col :xl="8" :lg="8" :md="12" :sm="24" :xs="24">
              <a-form-model-item label="库管员">
                <div>: {{ Form.cwhsmanagerid_dictText }}</div>
              </a-form-model-item>
            </a-col>
          </a-row>
        </a-form-model>

        <!-- 表格 -->
        <div class="print-table" style="margin-top: 10px">
          <table
            style="width: 100%; text-align: center; border-collapse: collapse"
            border="0"
            cellspacing="0"
            cellpadding="0"
          >
            <tr>
              <th>存货名称</th>
              <th>规格</th>
              <th>单位</th>
              <th>数量</th>
              <th>金额</th>
              <th>备注</th>
            </tr>
            <tr v-for="(item, index) in printDataSource" :key="index">
              <th>{{ item.inventoryName }}</th>
              <th>{{ item.standardModel }}</th>
              <th>{{ item.unit }}</th>
              <th>{{ item.quantity }}</th>
              <th>{{ item.money }}</th>
              <th>{{ item.remark }}</th>
            </tr>
          </table>
        </div>

        <!-- 尾部信息 -->
        <div class="print-footer" style="margin-top: 10px">
          <div style="margin-left: 10px">
            制单人： {{ Form.singleProducer }}
          </div>
        </div>
      </div>
    </div>
  </a-card>
</template>

<script>
import { CommonAjax } from "@/services/modules/common";
const comHttp = new CommonAjax(); // 公用接口

// import axios from "axios";

let columns = [
  {
    title: "序号",
    dataIndex: "key",
    key: "key",
    align: "center",
    width: "80px",
  },
  // {
  //   title: "仓库编码",
  //   key: "depotNo",
  //   dataIndex: "depotNo",
  //   align: "center",
  // },
  // {
  //   title: "仓库名称",
  //   key: "depotName",
  //   dataIndex: "depotName",
  //   align: "center",
  // },
  // {
  //   title: "库位",
  //   key: "depotLocation",
  //   dataIndex: "depotLocation",
  //   align: "center",
  // },
  // {
  //   title: "仓位",
  //   key: "position",
  //   dataIndex: "position",
  //   align: "center",
  // },
  // {
  //   title: "所属单位",
  //   key: "storageUnit",
  //   dataIndex: "storageUnit",
  //   align: "center",
  // },
  {
    title: "存货编码",
    dataIndex: "invcode",
    key: "invcode",
    align: "center",
  },
  {
    title: "存货名称",
    dataIndex: "invname",
    key: "invname",
    align: "center",
  },
  {
    title: "规格型号",
    dataIndex: "invspec",
    key: "invspec",
    align: "center",
  },
  {
    title: "单位",
    key: "measname",
    dataIndex: "measname",
    align: "center",
  },
  {
    title: "辅助单位",
    key: "auxiliaryUnit",
    dataIndex: "auxiliaryUnit",
    align: "center",
  },
  {
    title: "退库数量",
    key: "quantity",
    dataIndex: "quantity",
    align: "center",
  },
  // {
  //   title: "单价",
  //   key: "unitPrice",
  //   dataIndex: "unitPrice",
  //   align: "center",
  // },
  // {
  //   title: "金额",
  //   key: "money",
  //   dataIndex: "money",
  //   align: "center",
  // },
  {
    title: "源单单号",
    key: "sourceNumber",
    dataIndex: "sourceNumber",
    align: "center",
  },
  // {
  //   title: "批次号",
  //   key: "batchNumber",
  //   dataIndex: "batchNumber",
  //   align: "center",
  // },
  // {
  //   title: "是否赠品",
  //   key: "giveaway",
  //   dataIndex: "giveaway",
  //   align: "center",
  //   width: "120px",
  // },
  // {
  //   title: "退库日期",
  //   key: "deliveryDate",
  //   dataIndex: "deliveryDate",
  //   align: "center",
  // },
  {
    title: "备注",
    dataIndex: "remark",
    key: "remark",
    align: "center",
  },
];
export default {
  data() {
    return {
      u8c_array: [], //u8c传递数据表格的数据源
      arr: [], //销售订单子表
      arrOut: [], //销售出库单子表
      GeneralBillVO_46: [], //需给用友传递的data
      ayyanyany: [], //销售订单主表
      ayyanyanyOut: [], //销售出库单主表
      dataList: [], //u8c全部数据
      updateSucessRecordTag: false, //同步至u8c按钮的状态

      Form: {
        id: "", // id
        document: "", // 单据号
        document_date: "", // 单据日期
        depotName: "", // 仓库名称
        depotNo: "", // 仓库编号
        depotId: "", // 仓库Id
        storageUnit: "", // 所属单位名称
        storageUnitId: "", // 所属单位Id
        storageUnitNo: "", // 所属单位编号
        department: "", // 部门名称
        deptId: "", // 部门id
        client: "", // 客户名称
        clientId: "", // 客户Id
        sendReceiveType: "", // 收发类别名称
        sendReceiveTypeId: "", // 收发类别Id
        responsiblePerson: "", // 负责人名称
        responsiblePersonId: "", // 负责人Id
        inspector: "", // 审核人名称
        inspectorId: "", // 审核人Id
        balance: "", // 审核日期
        singleProducer: "", // 制单人名称
        singleProducerId: "", // 制单人Id
        cbiztype_dictText: "", // 业务流程名称
      },

      saleForm: {},
      // 格式
      layout: {
        labelCol: { span: 8 },
        wrapperCol: { span: 15 },
      },

      columns,
      dataSource: [],
      // autoSize: {
      //   x: 3500,
      //   y: 670,
      // },
      alreadyCheckTag: false, // 可以审核
      alreadyRecordTag: true, // 可以记账

      printDataSource: [],
    };
  },
  mounted() {
    this.initInfoMount();
  },
  watch: {
    $route() {
      this.initInfoMount();
    },
  },

  methods: {
    /**
   //todo @description: 反审核功能conCheck
   * @description: 登陆人 = 审核人 可以反审核
   * @description: 审核按钮与反审核按钮互斥
   * @return
   */
    conCheck() {
      var lanPerson = this.$store.state.user.info.id; //获取登陆人

      //登陆人 = 审核人 跳转编辑页面
      if (this.Form.inspectorId == lanPerson) {
        let data = {
          id: this.Form.id,
          auditMark: 2,
          balance: this.Form.balance,
        };

        // 提交审核信息，修改表一数据
        comHttp.updateStockReturnInfo(data).then((res) => {
          if (res.code == 200) {
            this.$message.success("反审核成功");
            this.alreadyCheckTag = false;
            this.$router.push({
              path: "saleOutCancelApple",
              query: {
                Id: this.Form.id,
                document: this.Form.document,
                singleProducer: this.Form.singleProducer,
              },
            });
          } else {
            this.$message.success("反审核失败");
          }
        });
      } else {
        this.$message.error("审核人才有权限");
      }
    },
    //
    initInfoMount() {
      if (typeof this.$route.query.Id != "undefined") {
        console.log("--------- 更新视图 销售退库  ----------");
        this.setInitInfo(this.$route.query.Id);
      }
    },
    // 审核函数
    Examine() {
      // this.Form.balance = moment().format("YYYY-MM-DD");
      console.log(this.Form.balance);
      let data = {
        id: this.Form.id,
        auditMark: 1,
        balance: this.Form.balance,
      };

      // 提交审核信息，修改表一数据
      comHttp.updateStockReturnInfo(data).then((res) => {
        if (res.code == 200) {
          this.$message.success("审核成功");
          this.alreadyCheckTag = false;
        } else {
          this.$message.success("审核失败");
        }
      });
    },

    // 路由跳转,设置初始化信息
    setInitInfo(id) {
      comHttp.getOutStorageApplyInfoById("?id=" + id).then((res) => {
        if (res.result.list[0].auditMark == 2) {
          this.alreadyCheckTag = true; // 未审核
        } else {
          this.alreadyCheckTag = false; // 已审核
        }

        console.log(res);
        this.Form = {};
        this.dataSource = [];
        /* ------------- 设置表单信息 -------------- */
        this.Form.id = res.result.list[0].id;
        this.Form.document = res.result.list[0].document;
        this.$set(this.Form, "document_date", res.result.list[0].documentDate);
        // 仓库名称
        this.Form.storname = res.result.list[0].storname;
        // 部门
        this.Form.deptId_dictText = res.result.list[0].deptId_dictText;
        // 所属仓库

        // 客户
        this.Form.clientId_dictText = res.result.list[0].clientId_dictText;
        // 业务类型
        this.Form.cbiztype_dictText = res.result.list[0].cbiztype_dictText;

        // 库管员
        this.Form.cwhsmanagerid_dictText =
          res.result.list[0].cwhsmanagerid_dictText;

        // 库存组织
        this.Form.pkCalbody_dictText = res.result.list[0].pkCalbody_dictText;

        // 收发类别
        this.Form.sendReceiveType_dictText =
          res.result.list[0].sendReceiveType_dictText;

        // 审核人
        this.$set(this.Form, "inspectorId", res.result.list[0].inspector);
        this.$set(
          this.Form,
          "inspector",
          res.result.list[0].inspector_dictText
        );

        this.Form.balance = res.result.list[0].balance; // 审核日期

        // 制单人
        this.Form.singleProducerName =
          res.result.list[0].singleProducer_dictText;

        let i = 0;
        res.result.list.forEach((element) => {
          let data = {
            id: element.twoId,
            key: i + 1,
            invname: element.invname,
            invcode: element.invcode,
            invspec: element.invspec,
            measname: element.measname,
            auxiliaryUnit: element.auxiliaryUnit_dictText,
            sourceNumber: element.sourceNumber,
            remark: element.remark,
            quantity: element.quantity,
          };
          i = i + 1;
          this.dataSource.push(data);
        });
      });
    },
  },
};
</script>

<style>
.print-table table td,
.print-table table th,
.print-table table tr {
  border: 1px solid black;
}
.print-table table tr {
  height: 30px;
}
</style>
